# 导入库函数
import requests
import json

from config import config_run
import time

localtime = time.strftime("%Y-%m-%dT%H:%M:%S", time.localtime())

config = config_run()
APIKEY = config[0]
device_id = config[1]
datastream_id = config[2]


# 结合API调试，定义参数
# url，此处device_id替换为自己的设备ID
# url = 'http://api.heclouds.com/devices/device_id/datapoints'
url = ('http://api.heclouds.com/devices/' + device_id + '/datapoints')

# # 生成指定格式的header
headers = {
    "api-key": APIKEY
}

# # 生成JSON数据流，对应数据流名称temp，值为25
dict = {
    "datastreams": [
        {
            "id": "Lum",
            "datapoints": [
                {
                    "at": localtime,
                    "value": 36
                },
                {
                    "at": localtime,
                    "value": 37
                },
                {
                    "at": localtime,
                    "value": 38
                }
            ]
        }
    ]
}
data = json.dumps(dict)

print('1', 20 * '*')
print('上传数据内容：',data)
# # 采用HTTP协议上传数据
response = requests.post(url, headers=headers, data=data)

# # 打印从OneNET平台收到的反馈信息
print(response.headers)
print('1', 20 * '*')
print(response.text)
print('2', 20 * '*')
